Skip to content

feat: add click-to-delete functionality for canvas connection lines - #145

Open
Kesarchauhan wants to merge 1 commit into
FOSSEE:masterfrom
Kesarchauhan:feat/click-to-delete-connections
Open

Kesarchauhan wants to merge 1 commit into
FOSSEE:masterfrom
Kesarchauhan:feat/click-to-delete-connections

Conversation

@Kesarchauhan

Copy link
Copy Markdown

Summary

  • Implements Task 3: Interactive click-to-delete functionality for connection lines (NodeLine) on the flowsheet canvas, allowing users to inspect, select, and delete individual stream connections directly without removing connected unit operations or material streams.
  • Canvas Graphics, Hit-Box & Visual Feedback (src/main/python/utils/Graphics.py):
    • Enabled QtWidgets.QGraphicsItem.ItemIsSelectable and QtWidgets.QGraphicsItem.ItemIsFocusable flags alongside hover event tracking (setAcceptHoverEvents(True)) and left/right mouse button acceptance (Qt.LeftButton | Qt.RightButton) on NodeLine.
    • Overrode NodeLine.shape() using a 10.0px-wide QtGui.QPainterPathStroker around the orthogonal connection path so users can reliably hover over and click 2px lines without pixel-hunting, while preserving the draggable free-endpoint ellipse hit-box for partial/rerouted connections.
    • Updated NodeLine.paint() to render distinct visual states: a blue highlight (QColor(0, 123, 255), 3px stroke) on hover, a red highlight (QColor(220, 53, 69), 3px stroke) when selected, and the default teal stroke (QColor(0, 70, 70, 220), 2px stroke) otherwise.
    • Implemented hoverEnterEvent() and hoverLeaveEvent() on NodeLine to drain any stale QApplication override cursors left on the stack by socket connections and apply QtCore.Qt.PointingHandCursor across both QApplication and the QGraphicsView viewport, restoring the default cursor automatically when leaving or deleting a hovered line.
  • Deletion Triggers & Model/Canvas Synchronization (src/main/python/utils/Graphics.py):
    • Updated NodeLine.mousePressEvent() to select the clicked connection line (clearing prior selection unless Ctrl is held) and assign keyboard focus (setFocus()), while keeping partial-line free-endpoint dragging intact.
    • Added a right-click contextMenuEvent() on NodeLine that selects the line and presents a Delete Connection action.
    • Added keyPressEvent() handling on NodeLine so pressing Delete or Backspace while a connection line is selected removes it immediately.
    • Implemented NodeLine.delete_connection() routed through Container.delete([self]) (with standalone fallback cleanup when no container is attached) so deleting a line cleanly detaches socket references (source.out_lines and target.in_lines), removes logical backend mappings (remove_connection(0, ...) and remove_connection(1, ...)), refreshes crossing hop arcs on neighboring lines, unlocks downstream component parameters via update_components_editability(), and records a canvas snapshot for Ctrl + Z Undo/Redo.
  • Automated Unit Testing (tests/test_node_line_delete.py):
    • Added 6 dedicated unit tests in tests/test_node_line_delete.py verifying:
      1. ItemIsSelectable and ItemIsFocusable flags and 10px QPainterPathStroker hit-box containment (test_nodeline_is_selectable_and_has_wide_hitbox).
      2. Hover state transitions and active paint() rendering for hovered and selected states (test_nodeline_hover_and_selection_paint).
      3. Container-backed deletion (Container.delete([self])) removing the line from the QGraphicsScene, detaching socket lists, invoking remove_connection on both connected unit operations, triggering update_components_editability(), and pushing an undo snapshot (test_nodeline_delete_via_container_updates_editability).
      4. Keyboard deletion via Qt.Key_Delete when the connection line is selected (test_nodeline_keyboard_delete_key).
      5. Right-click context menu Delete Connection execution (test_nodeline_context_menu_delete).
      6. Isolation during deletion so removing one connection line leaves unrelated connections on the canvas intact (test_deleting_one_line_preserves_other_connections).
    • Verified full regression suite passes with 342/342 tests passing (pytest --cov=python.utils.Graphics --cov-report=term-missing).

Demo Screenshots

Screenshot (838) Screenshot (839) Screenshot (840) Screenshot (841)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant